using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Xml;
using System.Text;
using IGlobalist.Cms.Model;
using IGlobalist.Cms.Bll;

namespace IGlobalist.Cms
{
    public partial class RSSFeed : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindList();
        }
        public void BindList()
        {
            Response.ContentType = "text/xml";
            try
            {
                string urlRoot = Request.Url.AbsoluteUri;
                urlRoot = urlRoot.Substring(0, urlRoot.LastIndexOf("/"));
                Response.Clear();
                XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
                objX.Namespaces = true;
                objX.WriteStartDocument();
                objX.WriteStartElement("rss");

                string description = @"";
                objX.WriteAttributeString("version", "2.0");

                objX.WriteStartElement("channel");
                objX.WriteElementString("title", "OneEducation Community");
                objX.WriteElementString("link", String.Format("{0}/0_0_0/Default.aspx", urlRoot));
                objX.WriteElementString("description", description);


                objX.WriteStartElement("image");
                objX.WriteElementString("title", "OneEducation");
                objX.WriteElementString("url", String.Format("{0}/Themes/Standard/Images/ex_logo.jpg", urlRoot.ToLower()));
                objX.WriteElementString("link", String.Format("{0}/0_0_0/Default.aspx", urlRoot.ToLower()));
                objX.WriteElementString("width", "200");
                objX.WriteElementString("height", "190");
                objX.WriteEndElement();
                IList<IContent> contentList = ContentController.GetContentListAvailable();
                foreach (IContent content in contentList)
                {
                    objX.WriteStartElement("item");
                    objX.WriteElementString("title", content.Title);
                    objX.WriteElementString("description", content.Description);
                    objX.WriteElementString("link", String.Format("{0}/{1}_0_{2}/Defaul.aspx", urlRoot.ToLower(),content.PageID ,content.ID));
                    objX.WriteElementString("pubDate", content.CreatedDate.ToLongDateString());
                    objX.WriteEndElement();
                }

                objX.WriteEndElement();
                objX.WriteEndDocument();

                objX.Flush();
                objX.Close();
            }
            catch (Exception ex)
            {
                Response.Write(String.Format("<rsserror>Rss Feed generation error: {0}{1}</rsserror>", ex.Message, ex.StackTrace));
            }
        }

    }
}
